﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http.Dispatcher;

namespace Xinchen.SOA.Server.ServiceHosting
{
    public class HttpControllerActivitor : DefaultHttpControllerActivator
    {
        public new System.Web.Http.Controllers.IHttpController Create(System.Net.Http.HttpRequestMessage request, System.Web.Http.Controllers.HttpControllerDescriptor controllerDescriptor, Type controllerType)
        {
            var httpController = base.Create(request, controllerDescriptor, controllerType);
            IEnumerable<string> applicationIds = new List<string>();
            request.Headers.TryGetValues("ApplicationId", out applicationIds);
            ((ServiceObject)httpController).ApplicationId = Convert.ToInt32(applicationIds.FirstOrDefault());
            return httpController;
        }
    }
}
